//
//  TravelDetailHeaderTableViewCell.swift
//  AirTravel
//
//  Created by apple on 2021/11/24.
//

import UIKit

class TravelDetailHeaderTableViewCell: UITableViewCell {

    

    @IBOutlet weak var tsLabel: UILabel!
    @IBOutlet weak var mapBt: UIButton!
    @IBOutlet weak var detailBt: UIButton!
    @IBOutlet weak var adress: UILabel!
    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var collectionView: UICollectionView!
    @IBOutlet weak var title: UILabel!
    
    var dataSouce = ["舒适" , "美丽"]
    override func awakeFromNib() {
        super.awakeFromNib()
        collectionView.delegate = self
        collectionView.dataSource = self
        
        let flowLayout = JYEqualCellSpaceFlowLayout(AlignType.left, 7.0)
        self.collectionView?.collectionViewLayout = flowLayout
        self.collectionView?.isScrollEnabled = false
        
        self.collectionView?.showsVerticalScrollIndicator = true
        
        self.collectionView?.register(UINib.init(nibName: "TagColl", bundle: nil), forCellWithReuseIdentifier: "TagColl")
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}


extension TravelDetailHeaderTableViewCell:UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        return self.dataSouce.count 
        
        
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TagColl", for: indexPath) as! TagColl
   
            cell.contentLab.font = UIFont.systemFont(ofSize: 10)
            cell.contentLab.layer.cornerRadius = 2
            cell.contentLab.layer.borderColor = UIColor(red: 165.0 / 255.0, green: 165.0 / 255.0, blue: 165.0 / 255.0, alpha: 1.0).cgColor
            cell.contentLab.layer.borderWidth = 1
            cell.contentLab.backgroundColor = UIColor.white
        cell.contentLab.text = dataSouce[indexPath.row]

            
        
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
        
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
   
            let attr_value = "\(self.dataSouce[indexPath.row])"
            var width = getLabWidth(labelStr: attr_value, font: UIFont.systemFont(ofSize: 10), height: 15)
            if width < 20 {
                width = 20
            }
            return CGSize.init(width: width + 10, height: 15)
            

    }
    
}
